var utils = require('../../../../utils/util.js') 
Page({

    /**
     * 页面的初始数据
     */
    data: {
        userinfo: [],
        username: "",
        token:""
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            userinfo: wx.getStorageSync("userinfo"),
            token: wx.getStorageSync("userinfo").wap_token
        })
    },
    editUsername: function (e) {
        this.setData({
            username: e.detail.value
        })
    },
    editUser: function () {
        var username = this.data.username;
        var token = this.data.token;
        var data = {
            url: "/v1/user/edit",
            token:token,
            ext:"name",
            value:username
        };
        utils.request(data).then(function (res) {
            if (res.code == 0) {
                wx.showToast({
                    title: "修改成功",
                    icon: 'none',
                    duration: 1500
                })
                utils.updateUserinfo();
                setTimeout(function () {
                    wx.navigateBack({
                        delta: 1
                    })
                }, 1500);
            } else {
                wx.showToast({
                    title: res.msg,
                    icon: 'none',
                    duration: 1500
                })
            }
        });
    },



})